package org.nowcoder.leetcode.twoPointers;

/**
 * Title  : 83. Remove Duplicates from Sorted List
 * Source : https://leetcode.cn/problems/remove-duplicates-from-sorted-list/description/
 * Author : XrazYang
 * Date   : 2023-10-21
 */

public class LeetCode_83 {
    class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public ListNode deleteDuplicates(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode p = head, q = p;
        while (q != null) {
            if (p.val != q.val) {
                p.next = q;
                p = q;
            }
            q = q.next;
        }
        p.next = null; //处理这种类型case: 1 2 3 3
        return head;
    }
}
